﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HA.Data;

namespace HA.ModFlow.Controls
{
    public class PCGridCell
    {
        public PCGridCell(Project project,List<int> indices)
        {
            this._project = project;


            this._indices = indices;


            if (this._project.MfData!=null)
            {
                _modflowCell = new PCModflowCell(project,indices);



                
            }

            if (this._project.Mt3dmsData!=null)
            {
                this._mtCell = new PCMT3DMSCell(project, indices);
                
            }
 
        }


        List<int> _indices;

        public List<int> Indices
        {
            get { return _indices; }
            set { _indices = value; }
        }

        Project _project;

        PCModflowCell _modflowCell;

        public PCModflowCell ModflowCell
        {
            get { return _modflowCell; }
            set { _modflowCell = value; }
        }

        PCMT3DMSCell _mtCell;

        public PCMT3DMSCell MtCell
        {
            get { return _mtCell; }
            set { _mtCell = value; }
        }



        public void Confirm(Project project)
        {
            if (this._modflowCell!=null)
            {

                this._modflowCell.Confirm(project,_indices);
            }

            if (this._mtCell != null)
            {
                this._mtCell.Confirm(project, _indices);
            }
        }

    }


    public class PCModflowCell
    {


        public PCModflowCell(Project project, List<int> indices)
        {


         




            ///循环法读取对应的设置
            ///
            for (int index = 0; index < indices.Count; index++)
            {

            

                int i, j, k;



                int[] ijk = project.MfData.GridData.GetIJK(indices[index]);
                i = ijk[0];
                j = ijk[1];
                k = ijk[2];


                ///第一次循环赋予初始值

                if (index == 0)
                {

                    this.BottomElevation = project.MfData.GridData.Elevations[k][i - 1, j - 1];
                    this.TopElevation = project.MfData.GridData.Elevations[k - 1][i - 1, j - 1];
                    this.Ibound = project.MfData.GridData.WaterGrid.GetIBounds()[k - 1][i - 1, j - 1];

                    this.Hk = project.MfData.FlowData.Hk.Datas[i - 1, j - 1,k-1];

                    this.StartingHead = project.MfData.GridData.WaterGrid.GetInitHead()[k - 1][i - 1, j - 1];

                    this.Hani = project.MfData.FlowData.LpfData.Hani.Datas[i - 1, j - 1,k-1];

                    this.Vani = project.MfData.FlowData.LpfData.Vka.Datas[i - 1, j - 1,k-1];

                    this.Leakance = project.MfData.FlowData.BcfData.Leakance.Datas[i - 1, j - 1, k - 1];

                    this.Sf1 = project.MfData.FlowData.BcfData.PrimaryStorage.Datas[i - 1, j - 1, k - 1];
                    this.Sf2 = project.MfData.FlowData.BcfData.SecondaryStorage.Datas[i - 1, j - 1, k - 1];
                    this.Transmissivity = project.MfData.FlowData.BcfData.Transmissivity.Datas[i - 1, j - 1, k - 1];
                    this.Ss = project.MfData.FlowData.LpfData.Ss.Datas[i - 1, j - 1, k - 1];
                    this.Sy = project.MfData.FlowData.LpfData.Sy.Datas[i - 1, j - 1, k - 1];

                    this.WetDry = project.MfData.FlowData.WetDry.Datas[i - 1, j - 1, k - 1];
                }

                else
                {
                    if (this.BottomElevation!=null)
                    {
                        if (this.BottomElevation!=project.MfData.GridData.Elevations[k][i - 1, j - 1])
                        {                            
                            this.BottomElevation=null;
                        }
                    }

                    if (this.TopElevation != null)
                    {
                        if (this.TopElevation != project.MfData.GridData.Elevations[k - 1][i - 1, j - 1])
                        {
                            this.TopElevation = null;
                        }                        
                    }
                    if (this.Ibound != null)
                    {
                        if (this.Ibound != project.MfData.GridData.WaterGrid.GetIBounds()[k - 1][i - 1, j - 1])
                        {
                            this.Ibound = null;
                        }
                    }
                    if (this.Hk != null)
                    {
                        if (this.Hk != project.MfData.FlowData.Hk.Datas[i - 1, j - 1, k - 1])//.InnerData.Layers[k - 1].HK[i - 1, j - 1])
                        {
                            this.Hk = null;
                        }
                    }
                    if (this.StartingHead != null)
                    {
                        if (this.StartingHead != project.MfData.GridData.WaterGrid.GetInitHead()[k - 1][i - 1, j - 1])
                        {
                            this.StartingHead = null;
                        }
                    }
                    if (this.Hani != null)
                    {
                        if (this.Hani != project.MfData.FlowData.LpfData.Hani.Datas[i - 1, j - 1, k - 1])// InnerData.Layers[k - 1].LpfLayer.HANI[i - 1, j - 1])
                        {
                            this.Hani = null;
                        }
                    }
                    if (this.Vani != null)
                    {
                        if (this.Vani != project.MfData.FlowData.LpfData.Vka.Datas[i - 1, j - 1, k - 1])// .InnerData.Layers[k - 1].LpfLayer.VKORVANI[i - 1, j - 1])
                        {
                            this.Vani = null;
                        }
                    }
                    if (this.Leakance != null)
                    {
                        if (this.Leakance != project.MfData.FlowData.BcfData.Leakance.Datas[i - 1, j - 1, k - 1])//.InnerData.Layers[k - 1].BcfLayer.SF1[i - 1, j - 1])
                        {
                            this.Leakance = null;
                        }
                    }
                    if (this.Sf1 != null)
                    {
                        if (this.Sf1 != project.MfData.FlowData.BcfData.PrimaryStorage.Datas[i - 1, j - 1, k - 1])//.InnerData.Layers[k - 1].BcfLayer.SF1[i - 1, j - 1])
                        {
                            this.Sf1 = null;
                        }
                    }
                    if (this.Sf2 != null)
                    {
                        if (this.Sf2 != project.MfData.FlowData.BcfData.SecondaryStorage.Datas[i - 1, j - 1, k - 1])//.InnerData.Layers[k - 1].BcfLayer.SF1[i - 1, j - 1])
                        {
                            this.Sf2 = null;
                        }
                    }
                    if (this.Transmissivity != null)
                    {
                        if (this.Transmissivity != project.MfData.FlowData.BcfData.Transmissivity.Datas[i - 1, j - 1, k - 1])//.InnerData.Layers[k - 1].BcfLayer.TRANSMISSITY[i - 1, j - 1])
                        {
                            this.Transmissivity = null;
                        }
                    }
                    if (this.Ss != null)
                    {
                        if (this.Ss != project.MfData.FlowData.LpfData.Ss.Datas[i - 1, j - 1, k - 1])//.InnerData.Layers[k - 1].LpfLayer.Ss[i - 1, j - 1])
                        {
                            this.Ss = null;
                        }
                    }
                    if (this.Sy != null)
                    {
                        if (this.Sy != project.MfData.FlowData.LpfData.Sy.Datas[i - 1, j - 1, k - 1])//.InnerData.Layers[k - 1].LpfLayer.Sy[i - 1, j - 1])
                        {
                            this.Sy = null;
                        }
                    }
                    if (this.WetDry != null)
                    {
                        if (this.WetDry != project.MfData.FlowData.WetDry.Datas[i - 1, j - 1, k - 1])//.InnerData.Layers[k - 1].LpfLayer.Sy[i - 1, j - 1])
                        {
                            this.WetDry = null;
                        }
                    }

                }
               



                
            }


          
 
        }




      







        double? _topElevation;

        public double? TopElevation
        {
            get { return _topElevation; }
            set { _topElevation = value; }
        }

        double? _bottomElevation;

        public double? BottomElevation
        {
            get { return _bottomElevation; }
            set { _bottomElevation = value; }
        }


        //Lpf包属性
        double? _hk;

        public double? Hk
        {
            get { return _hk; }
            set { _hk = value; }
        }

        double? _hani;

        public double? Hani
        {
            get { return _hani; }
            set { _hani = value; }
        }

        double? _vani;

        public double? Vani
        {
            get { return _vani; }
            set { _vani = value; }
        }

        double? _ss;

        public double? Ss
        {
            get { return _ss; }
            set { _ss = value; }
        }
        double? _sy;

        public double? Sy
        {
            get { return _sy; }
            set { _sy = value; }
        }

        //bcf属性
        double? _sf1;

        public double? Sf1
        {
            get { return _sf1; }
            set { _sf1 = value; }
        }

        double? _sf2;

        public double? Sf2
        {
            get { return _sf2; }
            set { _sf2 = value; }
        }

        double? _transmissivity;

        public double? Transmissivity
        {
            get { return _transmissivity; }
            set { _transmissivity = value; }
        }

        double? _leakance;

        public double? Leakance
        {
            get { return _leakance; }
            set { _leakance = value; }
        }

        //公共属性
        int? _ibound;

        public int? Ibound
        {
            get { return _ibound; }
            set
            {
                if (_ibound != value)
                {
                    _ibound = value;
                }
            }
        }

        double? _startingHead;

        public double? StartingHead
        {
            get { return _startingHead; }
            set { _startingHead = value; }
        }

        double? _porosity;

        public double? Porosity
        {
            get { return _porosity; }
            set { _porosity = value; }
        }

        double? _wetDry;

        public double? WetDry
        {
            get { return _wetDry; }
            set { _wetDry = value; }
        }



        public void Confirm(Project project, List<int> indices)
        {
            if (this._bottomElevation != null)
            {
                project.MfData.GridData.SetPartElevation(indices, (double)this._bottomElevation, false);

            }

            if (this._topElevation != null)
            {
                project.MfData.GridData.SetPartElevation(indices, (double)this._topElevation, true);

            }

            if (this._ibound != null)
            {
                project.MfData.GridData.WaterGrid.SetPartIBounds(indices, (int)this._ibound);

            }
            for (int index = 0; index < indices.Count; index++)
            {
                int i, j, k;


                int[] ijk = project.MfData.GridData.GetIJK(indices[index]);
                i = ijk[0];
                j = ijk[1];
                k = ijk[2];

                if (this.Hk != null)
                {
                    project.MfData.FlowData.Hk.Datas[i - 1, j - 1, k - 1] = (double)this.Hk;
                }
                if (this.StartingHead != null)
                {
                    project.MfData.GridData.WaterGrid.GetInitHead()[k - 1][i - 1, j - 1] = (double)this.StartingHead;
                }
                if (this.Hani != null)
                {
                    project.MfData.FlowData.LpfData.Hani.Datas[i - 1, j - 1, k - 1] = (double)this.Hani;
                }
                if (this.Vani != null)
                {
                    project.MfData.FlowData.LpfData.Vka.Datas[i - 1, j - 1, k - 1] = (double)this.Vani;
                }
                if (this.Leakance != null)
                {
                    project.MfData.FlowData.BcfData.Leakance.Datas[i - 1, j - 1, k - 1] = (double)this.Leakance;
                }
                if (this.Sf1 != null)
                {
                    project.MfData.FlowData.BcfData.PrimaryStorage.Datas[i - 1, j - 1, k - 1] = (double)this.Sf1;
                }
                if (this.Sf2 != null)
                {
                    project.MfData.FlowData.BcfData.SecondaryStorage.Datas[i - 1, j - 1, k - 1] = (double)this.Sf2;
                }
                if (this.Transmissivity != null)
                {
                    project.MfData.FlowData.BcfData.Transmissivity.Datas[i - 1, j - 1, k - 1] = (double)this.Transmissivity;
                }
                if (this.Ss != null)
                {
                    project.MfData.FlowData.LpfData.Ss.Datas[i - 1, j - 1, k - 1] = (double)this.Ss;
                }
                if (this.Sy != null)
                {
                    project.MfData.FlowData.LpfData.Sy.Datas[i - 1, j - 1, k - 1] = (double)this.Sy;
                }
                if (this.WetDry != null)
                {
                    project.MfData.FlowData.WetDry.Datas[i - 1, j - 1, k - 1] = (double)this.WetDry;
                }

            }

        }


        //int _zoneCode;

        //public int ZoneCode
        //{
        //    get { return _zoneCode; }
        //    set { _zoneCode = value; }
        //}

        //int _zoneBudgtId;

        //public int ZoneBudgtId
        //{
        //    get { return _zoneBudgtId; }
        //    set { _zoneBudgtId = value; }
        //}

        public object Clone()
        {
            return this.MemberwiseClone();
        }
    }

    public class PCMT3DMSCell
    {

        public PCMT3DMSCell(Project project, List<int> indices)
        {
            for (int index = 0; index < indices.Count; index++)
            {
                int[] ijk = project.MfData.GridData.GetIJK(indices[index]);
                int selectCellRow = ijk[0] - 1;
                int selectCellCol = ijk[1] - 1;
                int selectCellLayer = ijk[2] - 1;

                int layer = project.Mt3dmsData.BasicTransport.Grid.Nlayers;
                int row = project.Mt3dmsData.BasicTransport.Grid.Nrows;
                int col = project.Mt3dmsData.BasicTransport.Grid.Ncols;
                HA.ModFlow.Infrastructure.CellCenterDataSet3d cell;

                ///第一次循环赋予初始值
                if (index == 0)
                {
                    cell = project.Mt3dmsData.BasicTransport.Grid.GetICBoundDS();
                    this.Icbund = cell.Datas[selectCellRow, selectCellCol, selectCellLayer];

                    cell = new Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.BasicTransport.Grid.Elevations, project.Mt3dmsData.BasicTransport.Grid.GetICBUND(), row, col, layer);
                    this.Htop = cell.Datas[selectCellRow, selectCellCol, selectCellLayer];

                    cell = new Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.BasicTransport.Grid.GetPorosity(), project.Mt3dmsData.BasicTransport.Grid.GetICBUND(), row, col, layer);
                    this.Porosity = cell.Datas[selectCellRow, selectCellCol, selectCellLayer];

                    cell = new Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.Dispersion.AL, null, row, col, layer);
                    this.LongDispersivity = cell.Datas[selectCellRow, selectCellCol, selectCellLayer];

                    cell = new Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.ChemicalReaction.BulkDensity, null, row, col, layer);
                    this.BulkDensity = cell.Datas[selectCellRow, selectCellCol, selectCellLayer];

                    cell = new Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.ChemicalReaction.Porosity2, null, row, col, layer);
                    this.ImmobilePorosity = cell.Datas[selectCellRow, selectCellCol, selectCellLayer];

                    for (int i = 0; i < project.Mt3dmsData.ChemicalReaction.ChemicalSpecies.Count; i++)
                    {
                        Species sp = new Species();
                        sp.Name = project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].SpName;
                        cell = new HA.ModFlow.Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.BasicTransport.SpeciesCollecion.Species[i].InitConc, project.Mt3dmsData.BasicTransport.Grid.GetICBUND(), row, col, layer);
                        sp.StartConc =cell.Datas[selectCellRow, selectCellCol, selectCellLayer];
                        sp.IC = project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].SrcConc[selectCellLayer][selectCellRow, selectCellCol];
                        sp.Const1 = project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].Sp1[selectCellLayer][selectCellRow, selectCellCol];
                        sp.Const2 = project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].Sp2[selectCellLayer][selectCellRow, selectCellCol];
                        sp.Rate1 = project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].Rc1[selectCellLayer][selectCellRow, selectCellCol];
                        sp.Rate2 = project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].Rc2[selectCellLayer][selectCellRow, selectCellCol];
                        this.ArrySpecies.Add(sp);
                    }
                }

                else
                {
                    if (this.Icbund != null)
                    {
                        cell = project.Mt3dmsData.BasicTransport.Grid.GetICBoundDS();
                        if (this.Icbund != cell.Datas[selectCellRow, selectCellCol, selectCellLayer])
                        {
                            this.Icbund = null;
                        }
                    }

                    if (this.Htop != null)
                    {
                        cell = new Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.BasicTransport.Grid.Elevations, project.Mt3dmsData.BasicTransport.Grid.GetICBUND(), row, col, layer);
                        if (this.Htop != cell.Datas[selectCellRow, selectCellCol, selectCellLayer])
                        {
                            this.Htop = null;
                        }
                    }

                    if (this.Porosity != null)
                    {
                        cell = new Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.BasicTransport.Grid.GetPorosity(), project.Mt3dmsData.BasicTransport.Grid.GetICBUND(), row, col, layer);
                        if (this.Porosity != cell.Datas[selectCellRow, selectCellCol, selectCellLayer])
                        {
                            this.Porosity = null;
                        }
                    }

                    if (this.LongDispersivity != null)
                    {
                        cell = new Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.Dispersion.AL, null, row, col, layer);
                        if (this.LongDispersivity != cell.Datas[selectCellRow, selectCellCol, selectCellLayer])
                        {
                            this.LongDispersivity = null;
                        }
                    }

                    if (this.BulkDensity != null)
                    {
                        cell = new Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.ChemicalReaction.BulkDensity, null, row, col, layer);
                        if (this.BulkDensity != cell.Datas[selectCellRow, selectCellCol, selectCellLayer])
                        {
                            this.BulkDensity = null;
                        }
                    }

                    if (this.ImmobilePorosity != null)
                    {
                        cell = new Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.ChemicalReaction.Porosity2, null, row, col, layer);
                        if (this.ImmobilePorosity != cell.Datas[selectCellRow, selectCellCol, selectCellLayer])
                        {
                            this.ImmobilePorosity = null;
                        }
                    }


                    int[] ijk2 = project.MfData.GridData.GetIJK(indices[0]);
                    int a = ijk2[0] - 1;
                    int b = ijk2[1] - 1;
                    int c = ijk2[2] - 1;
                    for (int i = 0; i < project.Mt3dmsData.ChemicalReaction.ChemicalSpecies.Count; i++)
                    {
                         cell = new HA.ModFlow.Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.BasicTransport.SpeciesCollecion.Species[i].InitConc, project.Mt3dmsData.BasicTransport.Grid.GetICBUND(), row, col, layer);
                        if (this.ArrySpecies[i].StartConc != null)
                        {
                            if (this.ArrySpecies[i].StartConc != cell.Datas[selectCellRow, selectCellCol, selectCellLayer])
                            {
                                this.ArrySpecies[i].StartConc = null;
                            }
                        }

                        if (this.ArrySpecies[i].IC != null)
                        {
                            if (this.ArrySpecies[i].IC != project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].SrcConc[selectCellLayer][selectCellRow, selectCellCol])
                            {
                                this.ArrySpecies[i].IC = null;
                            }
                        }
                        if (this.ArrySpecies[i].Const1 != null)
                        {
                            if (this.ArrySpecies[i].Const1 != project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].Sp1[selectCellLayer][selectCellRow, selectCellCol])
                            {
                                this.ArrySpecies[i].Const1 = null;
                            }
                        }
                        if (this.ArrySpecies[i].Const2 != null)
                        {
                            if (this.ArrySpecies[i].Const2 != project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].Sp2[selectCellLayer][selectCellRow, selectCellCol])
                            {
                                this.ArrySpecies[i].Const2 = null;
                            }
                        }
                        if (this.ArrySpecies[i].Rate1 != null)
                        {
                            if (this.ArrySpecies[i].Rate1 != project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].Rc1[selectCellLayer][selectCellRow, selectCellCol])
                            {
                                this.ArrySpecies[i].Rate1 = null;
                            }
                        }
                        if (this.ArrySpecies[i].Rate2 != null)
                        {
                            if (this.ArrySpecies[i].Rate2 != project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].Rc2[selectCellLayer][selectCellRow, selectCellCol])
                            {
                                this.ArrySpecies[i].Rate2 = null;
                            }
                        }

                        //this.ArrySpecies[i].IC = project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].SrcConc[selectCellLayer][selectCellRow, selectCellCol];
                        //this.ArrySpecies[i].Const1 = project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].Sp1[selectCellLayer][selectCellRow, selectCellCol];
                        //this.ArrySpecies[i].Const2 = project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].Sp2[selectCellLayer][selectCellRow, selectCellCol];
                        //this.ArrySpecies[i].Rate1 = project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].Rc1[selectCellLayer][selectCellRow, selectCellCol];
                        //this.ArrySpecies[i].Rate2 = project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].Rc2[selectCellLayer][selectCellRow, selectCellCol];                      
                    }
                }
            }
        }

        private double? _icbund;

        public double? Icbund
        {
            get { return _icbund; }
            set { _icbund = value; }
        }


        private double? _htop;

        public double? Htop
        {
            get { return _htop; }
            set { _htop = value; }
        }

        private double? _porosity;

        public double? Porosity
        {
            get { return _porosity; }
            set { _porosity = value; }
        }


        private double? _longDispersivity;

        public double? LongDispersivity
        {
            get { return _longDispersivity; }
            set { _longDispersivity = value; }
        }


        private double? _bulkDensity;

        public double? BulkDensity
        {
            get { return _bulkDensity; }
            set { _bulkDensity = value; }
        }


        private double? _immobilePorosity;

        public double? ImmobilePorosity
        {
            get { return _immobilePorosity; }
            set { _immobilePorosity = value; }
        }



        private List<Species> _arrySpecies = new List<Species>();

        public List<Species> ArrySpecies
        {
            get { return _arrySpecies; }
            set { _arrySpecies = value; }
        }


        public void Confirm(Project project, List<int> indices)
        {
            if (project.Mt3dmsData == null)
            {
                return;
            }

            int layer = project.Mt3dmsData.BasicTransport.Grid.Nlayers;
            int row = project.Mt3dmsData.BasicTransport.Grid.Nrows;
            int col = project.Mt3dmsData.BasicTransport.Grid.Ncols;
            HA.ModFlow.Infrastructure.CellCenterDataSet3d cell;

            cell = project.Mt3dmsData.BasicTransport.Grid.GetICBoundDS();
            for (int i = 0; i < indices.Count; i++)
            {
                int[] ijk = project.Grid3dData.MainGrid.ModFlowGrid.GetIJK(indices[i]);
                int selectCellRow = ijk[0] - 1;
                int selectCellCol = ijk[1] - 1;
                int selectCellLayer = ijk[2] - 1;

                if (this.Icbund != null)
                {
                    cell.Datas[selectCellRow, selectCellCol, selectCellLayer] = (double)this.Icbund;
                }
            }
            project.Mt3dmsData.BasicTransport.Grid.SetICBoundDS(cell);

            cell = new Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.BasicTransport.Grid.Elevations, project.Mt3dmsData.BasicTransport.Grid.GetICBUND(), row, col, layer);
            for (int i = 0; i < indices.Count; i++)
            {
                int[] ijk = project.Grid3dData.MainGrid.ModFlowGrid.GetIJK(indices[i]);
                int selectCellRow = ijk[0] - 1;
                int selectCellCol = ijk[1] - 1;
                int selectCellLayer = ijk[2] - 1;

                if (this.Htop != null)
                {
                    cell.Datas[selectCellRow, selectCellCol, selectCellLayer] = (double)this.Htop;
                }
            }
            project.Mt3dmsData.BasicTransport.Grid.SetTopH(cell.ToListData());

            cell = new Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.BasicTransport.Grid.GetPorosity(), project.Mt3dmsData.BasicTransport.Grid.GetICBUND(), row, col, layer);
            for (int i = 0; i < indices.Count; i++)
            {
                int[] ijk = project.Grid3dData.MainGrid.ModFlowGrid.GetIJK(indices[i]);
                int selectCellRow = ijk[0] - 1;
                int selectCellCol = ijk[1] - 1;
                int selectCellLayer = ijk[2] - 1;

                if (this.Porosity != null)
                {
                    cell.Datas[selectCellRow, selectCellCol, selectCellLayer] = (double)this.Porosity;
                }
            }
            project.Mt3dmsData.BasicTransport.Grid.SetPorosity(cell.ToListData());


            cell = new Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.Dispersion.AL, null, row, col, layer);
            for (int i = 0; i < indices.Count; i++)
            {
                int[] ijk = project.Grid3dData.MainGrid.ModFlowGrid.GetIJK(indices[i]);
                int selectCellRow = ijk[0] - 1;
                int selectCellCol = ijk[1] - 1;
                int selectCellLayer = ijk[2] - 1;

                if (this.LongDispersivity != null)
                {
                    cell.Datas[selectCellRow, selectCellCol, selectCellLayer] = (double)this.LongDispersivity;
                }
            }
            project.Mt3dmsData.Dispersion.SetAL(cell.ToListData());

            cell = new Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.ChemicalReaction.BulkDensity, null, row, col, layer);
            for (int i = 0; i < indices.Count; i++)
            {
                int[] ijk = project.Grid3dData.MainGrid.ModFlowGrid.GetIJK(indices[i]);
                int selectCellRow = ijk[0] - 1;
                int selectCellCol = ijk[1] - 1;
                int selectCellLayer = ijk[2] - 1;

                if (this.BulkDensity != null)
                {
                    cell.Datas[selectCellRow, selectCellCol, selectCellLayer] = (double)this.BulkDensity;
                }
            }
            project.Mt3dmsData.ChemicalReaction.SetBulkDensity(cell.ToListData());

            cell = new Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.ChemicalReaction.Porosity2, null, row, col, layer);
            for (int i = 0; i < indices.Count; i++)
            {
                int[] ijk = project.Grid3dData.MainGrid.ModFlowGrid.GetIJK(indices[i]);
                int selectCellRow = ijk[0] - 1;
                int selectCellCol = ijk[1] - 1;
                int selectCellLayer = ijk[2] - 1;

                if (this.ImmobilePorosity != null)
                {
                    cell.Datas[selectCellRow, selectCellCol, selectCellLayer] = (double)this.ImmobilePorosity;
                }
            }
            project.Mt3dmsData.ChemicalReaction.SetPorosity2(cell.ToListData());



            for (int i = 0; i < project.Mt3dmsData.ChemicalReaction.ChemicalSpecies.Count; i++)
            {
                cell = new HA.ModFlow.Infrastructure.CellCenterDataSet3d(project.Mt3dmsData.BasicTransport.SpeciesCollecion.Species[i].InitConc, project.Mt3dmsData.BasicTransport.Grid.GetICBUND(), row, col, layer);
                for (int j = 0; j < indices.Count; j++)
                {
                    int[] ijk = project.Grid3dData.MainGrid.ModFlowGrid.GetIJK(indices[j]);
                    int selectCellRow = ijk[0] - 1;
                    int selectCellCol = ijk[1] - 1;
                    int selectCellLayer = ijk[2] - 1;

                    if (this.ArrySpecies[i].StartConc != null)
                    {
                        cell.Datas[selectCellRow, selectCellCol, selectCellLayer] = (double)this.ArrySpecies[i].StartConc;
                    }
                  

                    if (this.ArrySpecies[i].IC != null)
                    {
                        project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].SrcConc[selectCellLayer][selectCellRow, selectCellCol] = (double)this.ArrySpecies[i].IC;
                    }
                    if (this.ArrySpecies[i].Const1 != null)
                    {
                        project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].Sp1[selectCellLayer][selectCellRow, selectCellCol] = (double)this.ArrySpecies[i].Const1;
                    }
                    if (this.ArrySpecies[i].Const2 != null)
                    {
                        project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].Sp2[selectCellLayer][selectCellRow, selectCellCol] = (double)this.ArrySpecies[i].Const2;
                    }
                    if (this.ArrySpecies[i].Rate1 != null)
                    {
                        project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].Rc1[selectCellLayer][selectCellRow, selectCellCol] = (double)this.ArrySpecies[i].Rate1;
                    }
                    if (this.ArrySpecies[i].Rate2 != null)
                    {
                        project.Mt3dmsData.ChemicalReaction.ChemicalSpecies[i].Rc2[selectCellLayer][selectCellRow, selectCellCol] = (double)this.ArrySpecies[i].Rate2;
                    }
                }
                project.Mt3dmsData.BasicTransport.SpeciesCollecion.Species[i].SetInitConc(cell.ToListData());
            }
        }
    }

 public    class Species
    {
        private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private double? _StartConc;

        public double? StartConc
        {
            get { return _StartConc; }
            set { _StartConc = value; }
        }

        private double? _iC;

        public double? IC
        {
            get { return _iC; }
            set { _iC = value; }
        }


        private double? _const1;

        public double? Const1
        {
            get { return _const1; }
            set { _const1 = value; }
        }


        private double? _const2;

        public double? Const2
        {
            get { return _const2; }
            set { _const2 = value; }
        }


        private double? _rate1;

        public double? Rate1
        {
            get { return _rate1; }
            set { _rate1 = value; }
        }


        private double? _rate2;

        public double? Rate2
        {
            get { return _rate2; }
            set { _rate2 = value; }
        }

      
    }
}
